package com.zykj.demo;

import java.util.Observable;
import java.util.Observer;

/**
 * @author zhoulj(周利军) [1217102780@qq.com]
 * @Title: Javaer
 * @Project: ${MODEL_NAME}
 * @Module ID:   <(模块)类编号，可以引用系统设计中的类编号>
 * @Comments: <对此类的描述，可以引用系统设计中的描述>
 * @JDK version used:      <JDK1.8> 17
 * @since 2018/12/26-15:17
 */
public class Javaer implements Observer {
    String workName ;
    public Javaer(){}
    public Javaer(Observable observable) {
        //TODO 这里就是技巧
        observable.addObserver(this);
    }
    /**
     * This method is called whenever the observed object is changed. An
     * application calls an <tt>Observable</tt> object's
     * <code>notifyObservers</code> method to have all the object's
     * observers notified of the change.
     *
     * @param o   the observable object.
     * @param arg an argument passed to the <code>notifyObservers</code>
     */
    @Override
    public void update(Observable o, Object arg) {
        if (o instanceof Lietou) {
            Lietou l = (Lietou)o;
            this.workName = l.workName;
            System.out.println("arg:"+arg);
            work();
        }
    }

    public void work() {
        System.out.println(this.getClass().getName()+"  有工作：" + workName);
    }
}
